from rest_framework import serializers

from psychometry.models import Questionnaire, Psychometry
from user.serializers import UserInfoSerializer


class QuestionnaireSerializer(serializers.ModelSerializer):
	content = serializers.JSONField(source="get_content", read_only=True)
	createTime = serializers.CharField(source="create_time", read_only=True)
	qid = serializers.IntegerField(source="id", read_only=True)
	class Meta:
		model = Questionnaire
		exclude = ("create_time", "id")
		
class PsychometrySerializer(serializers.ModelSerializer):
	pid = serializers.IntegerField(source="id", read_only=True)
	user = UserInfoSerializer()
	questionnaire = QuestionnaireSerializer()
	analysis = serializers.JSONField(source="get_analysis", read_only=True)
	createTime = serializers.CharField(source="create_time", read_only=True)
	answerTime = serializers.CharField(source="answer_time", read_only=True)
	
	class Meta:
		model = Psychometry
		exclude = ("create_time", "answer_time", "id")
		
class PsychometrysSerializer(serializers.ModelSerializer):
	
	pid = serializers.IntegerField(source="id", read_only=True)
	createTime = serializers.CharField(source="create_time", read_only=True)
	answerTime = serializers.CharField(source="answer_time", read_only=True)
	class Meta:
		model = Psychometry
		fields = ("pid", "createTime", "answerTime")